/**
 * Created by arons on 16/6/30.
 */
var re1 = /ABC\-001/;
var re2 = new RegExp('ABC\\-001');

console.log(re1); // /ABC\-001/
console.log(re2); // /ABC\-001/

var re = /^\d{3}[ \-]\d{3,8}$/;
var testResult = re.test("010-321321");
console.log(testResult);
testResult = re.test("010-32132X");
console.log(testResult);
testResult = re.test("010 321321");
console.log(testResult);
testResult = re.test("010 -321321");
console.log(testResult);


var re = /^(\d{3})-(\d{3,8})$/;
testResult = re.exec('010-12345'); // ['010-12345', '010', '12345']
console.log(testResult);

testResult = re.exec('010 12345'); // null
console.log(testResult);

/**
 * 贪婪匹配
 */

re = /^(\d+)(0*)$/;
testResult = re.exec('102300'); // ['102300', '102300', '']
console.log(testResult);

re = /^(\d+?)(0*)$/;
testResult = re.exec('102300'); // ['102300', '1023', '00']
console.log(testResult);

console.log("=================");
var s = 'JavaScript, VBScript, JScript and ECMAScript';
re=/[a-zA-Z]+Script/g;

while(testResult = re.exec(s)){
    console.log(testResult, re.lastIndex);
}

